cti#!/usr/bin/nawk

BEGIN{
    sum=0;
    count_valid=0;
    null_count=0;
    count_inv=0;
    neg_count=0;
}

{
    if($c1=="") {
	null_count++;
	#print ("null c ++, $null_count");
    }
    if($c2==0) {
	if($c1<0) {
	    neg_count++;
	#    print("-cn",neg_count);
	}
	sum += $c1;
	count_valid++;
	#print("cv",count_valid);
    }
    if ($c2>0) {
	count_inv++;
	#print("e-ci",count_inv);
    }
}
END{
    if( count_valid<=7) {
	avg=NULL;
	abs_avg=NULL;
    }
    if( count_valid >= 8){
	avg=sum/count_valid;
	count_inv=NR-count_valid;
	abs_avg=sqrt(avg*avg);
    }
    if (avg<0) {
	pos_avg=NULL;
    }
    if (avg>=0) {
	pos_avg=avg;
    }
    if(flag==0) {
	if (NR==0){
	    printf(avg"-999,");
	}
	else if(avg==NULL) {
	    printf("-999,");
	}
	else print(avg",");
    }
    if(flag==1) {
	if(NR==0) {
	    printf("-999,-999,-999,-999,-999,-999,");
	}
	else if(avg==NULL) 
	    printf("-999,-999,-999,%d,%d,%d,",count_valid-neg_count,NR,count_inv);

	else if(avg<0) 
	    printf("%.2f,%.2f,-999,%d,%d,%d,", avg,abs_avg,count_valid-neg_count,NR,count_inv);
	
	else if(avg>=0) 
		printf("%.2f,%.2f,%.2f,%d,%d,%d,",avg,abs_avg,pos_avg,count_valid-neg_count,NR,count_inv);
	    
	
    }
}
